﻿<!DOCTYPE html>
<html>
<head>
    <title>JS Functions Exercise 2</title>
    <link href="styles/js-console.css" rel="stylesheet" />
</head>
<body>
    <h1>Function that reverses the digits of given decimal number.</h1>
    <label for="num-input">Number:</label>
    <input type="text" id="num-input" />
    <button onclick="execute()">Execute</button>
    <div id="js-console"></div>
    <script src="scripts/js-console.js"></script>
    <script>
        function reverseNumber(number)
        {
            var num_str = number.toString();
            var rev_str = "";

            for (var idx = num_str.length - 1; idx >= 0; idx--)
            {
                rev_str += num_str[idx];
            }

            return parseInt(rev_str);
        }

        function execute()
        {
            var num = jsConsole.readInteger("#num-input");
            jsConsole.writeLine(reverseNumber(num));
        }

    </script>
</body>
</html>
